<script setup>
import { ref } from "vue";
const menus = ref([]);

import { menuService } from "@/api/menuAPI.js";

const getMenuService = async () => {
  const result = await menuService();
  menus.value = result.data;
};
getMenuService();

import { useRouter } from "vue-router";
const router = useRouter();
// 点击跳转路由
const handleMenu = (menu) => {
  router.push(menu.path);
}
</script>
<template>
  <el-aside id="asideNav">
    <div class="logo-name">
      <p>颐养中心</p>
      <img src="@/assets/logo.png" class="logo-png" />
    </div>

    <!--菜单列表-->
    <el-menu
      active-text-color="#ffd04b"
      background-color="#3CA2E0"
      :default-active="$route.path"
      :router="true"
      unique-opened
      text-color="#fff"
    >
      <template v-for="(menu, idx) in menus" :key="idx">
        <el-sub-menu :index="menu.menusIndex">
          <template #title>
            <el-icon>
              <!-- 动态获取图标 -->
              <component :is="menu.icon" />
            </el-icon>
            <span>{{ menu.title }}</span>
          </template>
          <template v-for="(menu, idx) in menu.children" :key="idx">
            <el-menu-item :index="menu.path" @click="handleMenu(menu)"
              ><el-icon><component :is="menu.icon" /></el-icon
              >{{ menu.title }}</el-menu-item
            >
          </template>
        </el-sub-menu>
      </template>
    </el-menu>
  </el-aside>
</template>
<style scoped>
#asideNav {
  display: flex;
  flex-direction: column;
  width: 200px;
  height: 100vh;
}

#asideNav .logo-name {
  width: 100%;
  height: 150px;
  background-color: #3ca2e0;
}
#asideNav .logo-name .logo-png {
  width: 165px;
  height: 165px;
  margin: -30px 0 0 10px;
}
#asideNav .logo-name p {
  font-weight: 800;
  height: 50px;
  line-height: 50px;
  text-align: center;
  font-size: 25px;
  margin: 0px;
  color: #fff;
}

#asideNav .el-menu {
  /* font-weight: 550; */
  flex: 1;
  border-right: none;
}
</style>
